Introduction
This is a MCP23017-based IO expansion board that provides 16 additional IO ports for your microcontroller. It can be set up for 8 different addresses, which means that 8 modules can be connected through two IIC buses to achieve up to 128 IO extensions. This module is an excellent solution to the insufficient IO problem in applications like robots and interactive media.
This IO expansion board has 2 groups of IO pins: GPIOA and GPIOB. Each group has 8 independent IOs and each of them can be arbitrarily configured as input or output, and a pull-up input (connect to 100KΩ pull-up), interrupt and so on. Besides that, the module has 2 interrupt signal pins IA and IB which are used for detecting the interruption in the ports GPIOA and CPIOB respectively. When an interrupt occurs on one of the pin in CPIOA or GPIOB, the pin IA or IB will produce a High-level signal correspondingly.
Applications
- Robots
- Interactive Media
- Light Cube
Specification
- Power Supply: 3.3V-5.5V
- IIC Address: 0x20~0x27
- Digital IO/Input/Output: PA0-PA7, PB0-PB7
- IO Driving Current: 20mA
- Signal Interrupt Pin: IA, IB
- Dimension: 44x32mm / 1.73x1.26"
Board Overview



Num | Name | Description |
---|---|---|
1 | +/VCC | Positive |
2 | -/GND | Negative |
3 | C | IIC Clock Line |
4 | D | IIC Data Line |
5 | RST | Reset Pin |
6 | IA | GPIOA Interrupt Detection Pin |
7 | IB | GPIOB Interrupt Detection Pin |
8 | PWR | Power Indicator |
9 | A0/A1/A2 | IIC Address Switch |
Digital IO Port Table
CPIOA | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---|---|---|---|---|---|---|---|---|
PA0 | PA1 | PA2 | PA3 | PA4 | PA5 | PA6 | PA7 | |
CPIOB | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
PB0 | PB1 | PB2 | PB3 | PB4 | PB5 | PB6 | PB7 |
Each digital pin in the table can be arbitrarily configured as input or output, and a pull-up input, interrupt and so on.
Tutorial
Requirements
- Hardware
- DFRduino UNO R3 (or similar) x 1
- MCP23017 IIC to 16 Digital IO Expansion Module x1
- Buttons
- LED Modules
- Software
- Arduino IDE
- Download and install the MCP23017 Library (About how to install the library?)
API Function List
The Relation Between DIP and IIC Address
A2 | A1 | A0 | IIC Address |
---|---|---|---|
0 | 0 | 0 | 0x20 |
0 | 0 | 1 | 0x21 |
0 | 1 | 0 | 0x22 |
0 | 1 | 1 | 0x23 |
1 | 0 | 0 | 0x24 |
1 | 0 | 1 | 0x25 |
1 | 1 | 0 | 0x26 |
1 | 1 | 1 | 0x27(Default) |
Connection Diagram
Sample Code 1- Button Input
Set the pin PA0 of the board to input mode, connect it with a button. When the button is pressed, serial print the string "Button press!".
- Expected Results When the button is pressed, print the "Button press" on the serial port.
Sample Code 2- Pin Output
Set the pin PA7 of the board to output mode, connect it with an LED, and change the LED state in one minute.
- Expected Results
The LED connected with pin PA7 changes the state in one minute, serial print the Level output from Pin PA7.
Sample Code- Interrupt Polling
Set the IO pins of the board to interrupt mode, such as eChangeLevel, eFalling, eRising, eHighLevel, eLowLevel. Set PA0, PA1, PB6, PB7 to eChangeLevel, eFalling, eRising, eHighLevel respectively, poll and serial print the pins where interrupt happened.
- Expected Results
Press the button connected with PA0, PA1, PB6, PB7 to trigger interrupt, and serial print the pins where interrupt happened.
Sample Code 4- IO Interrupt
Combine the pin INTA and INTB of the expansion board and the external interrupt of UNO to realize IO interrupt. Before downloading the following sample code, connect the IA and IB of the expansion board to UNO digital pin 2(external interrupt 0) and pin 3(external interrupt 1). Set the pin PA0 to eHighLevel interrupt, PB7 to double edge interrupt and connect buttons with them. Set UNO external interrupts to rising edge interrupt. Execute the related interrupt service function when an interrupt occurs.
For other microcontroller, check the interrupt pin at the table in the sample code below.
- Expected Results
Press the button on PAO or PB7, the following result will be printed on the serial port.
Cascade Connection
FAQ
For any questions, advice or cool ideas to share, please visit the DFRobot Forum